import { createStore } from 'vuex';
// import createPersistedState from '@dcloudio/uni-h5';

const store =  createStore({
  // plugins: [
  //   createPersistedState({
  //     key: 'uni-app-storage',
  //     paths: ['todos', 'settings']
  //   })
  // ],
  state: {
    todos: [
      { text: '完成项目配置', completed: false },
      { text: '编写测试用例', completed: true },
      { text: '[紧急]修复样式问题', completed: false },
      { text: '[需求]用户调研分析', completed: true },
      { text: '部署测试环境', completed: false }
    ],
    settings: {
      theme: 'light',
      notifications: true
    }
  },
  mutations: {
    ADD_TODO(state, todo) {
      state.todos.push(todo);
    },
    TOGGLE_TODO(state, index) {
      state.todos[index].completed = !state.todos[index].completed;
    },
    UPDATE_THEME(state, theme) {
      state.settings.theme = theme;
      uni.setNavigationBarColor({
        frontColor: theme === 'dark' ? '#ffffff' : '#000000',
        backgroundColor: theme === 'dark' ? '#1a1a1a' : '#f5f5f5'
      });
    }
  },
  actions: {
    initializeTheme({ commit }) {
      const savedTheme = uni.getStorageSync('uni-app-storage')?.settings?.theme;
      commit('UPDATE_THEME', savedTheme || 'light');
    }
  }
});

export default store;